<?php
declare(strict_types=1);

namespace App\Logic\User\Service\Article;

use App\Logic\User\Repository\Article\ArticleContentRepository;
use App\Logic\User\Service\UserServiceInterface;
use Closure;

class ArticleContentService implements UserServiceInterface
{

    public static function searchWhere(array $requestParams): Closure
    {
        return function ($query) use ($requestParams) {
            extract($requestParams);
            $query->where("is_show", "=", 1);
            if (!empty($cate_uid)) {
                $query->where("cate_uid", "=", $cate_uid);
            }
            if (!empty($article_uid)) {
                $query->where("uid", "=", $article_uid);
            }
        };
    }

    public function serviceSelect(array $requestParams): array
    {
        return (new ArticleContentRepository())->repositorySelect(self::searchWhere($requestParams),
            (int)($requestParams["size"] ?? 20),
            ["cate_uid", "title", "uid"]
        );
    }

    public function serviceCreate(array $requestParams): array
    {
        return [];
    }

    public function serviceUpdate(array $requestParams): array
    {
        return [];
    }

    public function serviceDelete(array $requestParams): int
    {
        return 0;
    }

    public function serviceFind(array $requestParams): array
    {
        return (new ArticleContentRepository())->repositoryFind(self::searchWhere($requestParams),
            ["cate_uid", "content", "title"]);
    }
}
